home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / libhoward / part04 < prev    next >
Encoding:
Text File  |  1989-09-30  |  45.8 KB  |  1,523 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v08i082: libhoward portability library, part 4 of 9
  3. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: howard@dahlbeck.ericsson.se (Howard Gayle)
  5.  
  6. Posting-number: Volume 8, Issue 82
  7. Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle)
  8. Archive-name: libhoward/part04
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # If this archive is complete, you will see the following message at the end:
  17. #        "End of archive 4 (of 9)."
  18. # Contents:  a2i.c a2u.c a2ul.c freezePch.b getlin.c mopenp.c new.1
  19. #   port.h qrndu.c yrwk.c
  20. # Wrapped by howard@hasse on Mon Sep 25 07:08:08 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'a2i.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'a2i.c'\"
  24. else
  25. echo shar: Extracting \"'a2i.c'\" \(4221 characters\)
  26. sed "s/^X//" >'a2i.c' <<'END_OF_FILE'
  27. X/*
  28. X * a2i - convert Ada-syntax integer literal to int
  29. X */
  30. X
  31. X#ifndef lint
  32. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  33. X#endif lint
  34. X
  35. X/*
  36. X * This program is free software; you can redistribute it and/or modify
  37. X * it under the terms of the GNU General Public License version 1,
  38. X * as published by the Free Software Foundation.
  39. X *
  40. X * This program is distributed in the hope that it will be useful,
  41. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43. X * GNU General Public License for more details.
  44. X *
  45. X * You should have received a copy of the GNU General Public License
  46. X * along with this program; if not, write to the Free Software
  47. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  48. X */
  49. X
  50. X#include <stdio.h>
  51. X#include <howard/port.h>
  52. X#include <howard/version.h>
  53. X
  54. XMODVER ("@(#)$Header: a2i.c,v 1.7 89/08/10 13:02:15 howard Exp $");
  55. X
  56. X#include <errno.h>
  57. X#include <limits.h>
  58. X#include <howard/a2.h>
  59. X#include <howard/registers.i>
  60. X#include <howard/simultipre.i>
  61. X#include <howard/smp.h>
  62. X
  63. XPUBLIC int a2i (str, lim, synok, res, end)
  64. XbStrT  str;   /* Input string.*/
  65. XbStrT  lim;   /* Don't pass this.*/
  66. XboolT  synok; /* Accept non-fatal syntax errors.*/
  67. Xint   *res;   /* Points to where to store result.*/
  68. XbStrT *end;   /* End pointer stored here.*/
  69. X
  70. X/* Function:
  71. X *    
  72. X * Algorithm:
  73. X *    Call a2l(), then range check the result.
  74. X * Returns:
  75. X *    
  76. X * Notes:
  77. X *    
  78. X */
  79. X{
  80. XR1 int  s; /* Return code.*/
  81. X   long l; /* a2l() stores its result here.*/
  82. X
  83. Xs = a2l (str, lim, synok, &l, end);
  84. Xif (SUCCESS == s)
  85. X   {
  86. X   if ((l < ((long) INT_MIN)) || (l > ((long) INT_MAX)))
  87. X      s = ERANGE;
  88. X   else
  89. X      *res = l;
  90. X   }
  91. Xreturn (s);
  92. X}
  93. X
  94. X#ifdef TEST
  95. X#include <howard/usage.h>
  96. X
  97. XMAINVER ("@(#)$Header: a2i.c,v 1.7 89/08/10 13:02:15 howard Exp $");
  98. XUSAGE ("integer_numeric_literal");
  99. X
  100. X#include <string.h>
  101. X#include <howard/malf.h>
  102. X
  103. XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff)
  104. Xint num; /* Test number.*/
  105. XbStrT str; /* str argument.*/
  106. Xint limoff; /* Limit offset, -1 for none.*/
  107. XboolT synok; /* synok argument.*/
  108. Xint xrc; /* Expected return code.*/
  109. Xint xres; /* Expected result.*/
  110. Xint xendoff; /* Expected end offset.*/
  111. X{
  112. Xint rc; /* Return code.*/
  113. Xint res; /* Result stored here.*/
  114. XbStrT end; /* End string stored here.*/
  115. X
  116. Xrc = a2i (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end);
  117. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  118. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  119. X   PRINTF ("%d: res %d expected %d\n", num, res, xres);
  120. Xif (xendoff < 0) xendoff = strlen (str);
  121. Xif ((end - str) != xendoff)
  122. X   PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff);
  123. X}
  124. X
  125. XPUBLIC int main (argc, argv)
  126. Xint    argc; /* Number of arguments.*/
  127. XbStrT *argv; /* Points to array of argument strings.*/
  128. X{
  129. XbStrT end; /* End of string.*/
  130. Xint res; /* a2i() stores its result here.*/
  131. X
  132. X/*num str           limoff syn rc res  end */
  133. Xt(__LINE__,"12",              -1, 0, 0,           12, -1);
  134. Xt(__LINE__,"0",               -1, 0, 0,            0, -1);
  135. Xt(__LINE__,"1E6",             -1, 0, 0,      1000000, -1);
  136. Xt(__LINE__,"2#1111_1111#",    -1, 0, 0,          255, -1);
  137. Xt(__LINE__,"16#FF#",          -1, 0, 0,          255, -1);
  138. Xt(__LINE__,"016#0FF#",        -1, 0, 0,          255, -1);
  139. Xt(__LINE__,"16#E#E1",         -1, 0, 0,          224, -1);
  140. Xt(__LINE__,"2#1110_0000#",    -1, 0, 0,          224, -1);
  141. Xt(__LINE__,"012",              1, 0, 0,            0,  1);
  142. Xt(__LINE__,"-2_147_483_648",  -1, 0, 0,      INT_MIN, -1);
  143. Xt(__LINE__," \t2_147_483_647",-1, 1, 0,      INT_MAX, -1);
  144. Xt(__LINE__,"12B",             -1, 1, 0,           12,  2);
  145. Xt(__LINE__,"16#abcdef#.",     -1, 1, 0,     0xABCDEF, 10);
  146. X
  147. Xif (2 != argc) usage();
  148. Xswitch (a2i (argv[1], NULBSTR, FALSE, &res, &end))
  149. X   {
  150. X   case SUCCESS:
  151. X      PRINTF ("8#%o#\t10#%d#\t16#%X#\n", res, res, res);
  152. X      break;
  153. X   case EINVAL:
  154. X      PRINTF ("EINVAL %s\n", end);
  155. X      break;
  156. X   case EDOM:
  157. X      PRINTF ("EDOM %s\n", end);
  158. X      break;
  159. X   case ERANGE:
  160. X      PRINTF ("ERANGE %s\n", end);
  161. X      break;
  162. X   default:
  163. X      PUTS ("Unexpected return");
  164. X      break;
  165. X   }
  166. Xmfflush (stdout, "Standard Output");
  167. Xexit (SUCCESS);
  168. X
  169. X#ifdef lint
  170. Xreturn (SUCCESS);
  171. X#endif
  172. X}
  173. X#endif
  174. END_OF_FILE
  175. if test 4221 -ne `wc -c <'a2i.c'`; then
  176.     echo shar: \"'a2i.c'\" unpacked with wrong size!
  177. fi
  178. # end of 'a2i.c'
  179. fi
  180. if test -f 'a2u.c' -a "${1}" != "-c" ; then 
  181.   echo shar: Will not clobber existing file \"'a2u.c'\"
  182. else
  183. echo shar: Extracting \"'a2u.c'\" \(4270 characters\)
  184. sed "s/^X//" >'a2u.c' <<'END_OF_FILE'
  185. X/*
  186. X * a2u - convert Ada-syntax integer literal to unsigned
  187. X */
  188. X
  189. X#ifndef lint
  190. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  191. X#endif lint
  192. X
  193. X/*
  194. X * This program is free software; you can redistribute it and/or modify
  195. X * it under the terms of the GNU General Public License version 1,
  196. X * as published by the Free Software Foundation.
  197. X *
  198. X * This program is distributed in the hope that it will be useful,
  199. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  200. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  201. X * GNU General Public License for more details.
  202. X *
  203. X * You should have received a copy of the GNU General Public License
  204. X * along with this program; if not, write to the Free Software
  205. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  206. X */
  207. X
  208. X#include <stdio.h>
  209. X#include <howard/port.h>
  210. X#include <howard/version.h>
  211. X
  212. XMODVER ("@(#)$Header: a2u.c,v 1.6 89/08/11 14:08:33 howard Exp $");
  213. X
  214. X#include <errno.h>
  215. X#include <limits.h>
  216. X#include <howard/a2.h>
  217. X#include <howard/registers.i>
  218. X#include <howard/simultipre.i>
  219. X#include <howard/smp.h>
  220. X
  221. XPUBLIC int a2u (str, lim, synok, res, end)
  222. XbStrT     str;   /* Input string.*/
  223. XbStrT     lim;   /* Don't pass this.*/
  224. XboolT     synok; /* Accept non-fatal syntax errors.*/
  225. Xunsigned *res;   /* Points to where to store result.*/
  226. XbStrT    *end;   /* End pointer stored here.*/
  227. X
  228. X/* Function:
  229. X *    
  230. X * Algorithm:
  231. X *    Call a2smp() then smp2u().
  232. X * Returns:
  233. X *    
  234. X * Notes:
  235. X *    
  236. X */
  237. X{
  238. XR1 int  s;   /* Return code.*/
  239. X   smpT smp; /* a2smp() stores its result here.*/
  240. X
  241. Xs = a2smp (str, lim, synok, &smp, end);
  242. Xif (SUCCESS == s) s = smp2u (&smp, res);
  243. Xreturn (s);
  244. X}
  245. X
  246. X#ifdef TEST
  247. X#include <howard/usage.h>
  248. X
  249. XMAINVER ("@(#)$Header: a2u.c,v 1.6 89/08/11 14:08:33 howard Exp $");
  250. XUSAGE ("integer-numeric-literal");
  251. X
  252. X#include <string.h>
  253. X#include <howard/malf.h>
  254. X
  255. XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff)
  256. Xint num; /* Test number.*/
  257. XbStrT str; /* str argument.*/
  258. Xint limoff; /* Limit offset, -1 for none.*/
  259. XboolT synok; /* synok argument.*/
  260. Xint xrc; /* Expected return code.*/
  261. Xunsigned xres; /* Expected result.*/
  262. Xint xendoff; /* Expected end offset.*/
  263. X{
  264. Xint rc; /* Return code.*/
  265. Xunsigned res; /* Result stored here.*/
  266. XbStrT end; /* End string stored here.*/
  267. X
  268. Xrc = a2u (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end);
  269. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  270. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  271. X   PRINTF ("%d: res %u expected %u\n", num, res, xres);
  272. Xif (xendoff < 0) xendoff = strlen (str);
  273. Xif ((end - str) != xendoff)
  274. X   PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff);
  275. X}
  276. X
  277. XPUBLIC int main (argc, argv)
  278. Xint    argc; /* Number of arguments.*/
  279. XbStrT *argv; /* Points to array of argument strings.*/
  280. X{
  281. XbStrT end; /* End of string.*/
  282. Xunsigned res; /* a2u() stores its result here.*/
  283. X
  284. X/*num str           limoff syn rc res  end */
  285. Xt(__LINE__,"12",              -1, 0, 0, (unsigned)        12, -1);
  286. Xt(__LINE__,"0",               -1, 0, 0, (unsigned)         0, -1);
  287. Xt(__LINE__,"1E6",             -1, 0, 0, (unsigned)   1000000, -1);
  288. Xt(__LINE__,"2#1111_1111#",    -1, 0, 0, (unsigned)       255, -1);
  289. Xt(__LINE__,"16#FF#",          -1, 0, 0, (unsigned)       255, -1);
  290. Xt(__LINE__,"016#0FF#",        -1, 0, 0, (unsigned)       255, -1);
  291. Xt(__LINE__,"16#E#E1",         -1, 0, 0, (unsigned)       224, -1);
  292. Xt(__LINE__,"2#1110_0000#",    -1, 0, 0, (unsigned)       224, -1);
  293. Xt(__LINE__,"012",              1, 0, 0, (unsigned)         0,  1);
  294. Xt(__LINE__," \t2_147_483_647",-1, 1, 0, (unsigned)   INT_MAX, -1);
  295. Xt(__LINE__," \t4_294_967_295",-1, 1, 0, (unsigned)  UINT_MAX, -1);
  296. Xt(__LINE__,"12B",             -1, 1, 0, (unsigned)        12,  2);
  297. Xt(__LINE__,"16#abcdef#.",     -1, 1, 0, (unsigned)  0xABCDEF, 10);
  298. X
  299. Xif (2 != argc) usage();
  300. Xswitch (a2u (argv[1], NULBSTR, FALSE, &res, &end))
  301. X   {
  302. X   case SUCCESS:
  303. X      PRINTF ("8#%o#\t10#%u#\t16#%X#\n", res, res, res);
  304. X      break;
  305. X   case EINVAL:
  306. X      PRINTF ("EINVAL %s\n", end);
  307. X      break;
  308. X   case EDOM:
  309. X      PRINTF ("EDOM %s\n", end);
  310. X      break;
  311. X   case ERANGE:
  312. X      PRINTF ("ERANGE %s\n", end);
  313. X      break;
  314. X   default:
  315. X      PUTS ("Unexpected return");
  316. X      break;
  317. X   }
  318. Xmfflush (stdout, "Standard Output");
  319. Xexit (SUCCESS);
  320. X
  321. X#ifdef lint
  322. Xreturn (SUCCESS);
  323. X#endif
  324. X}
  325. X#endif
  326. END_OF_FILE
  327. if test 4270 -ne `wc -c <'a2u.c'`; then
  328.     echo shar: \"'a2u.c'\" unpacked with wrong size!
  329. fi
  330. # end of 'a2u.c'
  331. fi
  332. if test -f 'a2ul.c' -a "${1}" != "-c" ; then 
  333.   echo shar: Will not clobber existing file \"'a2ul.c'\"
  334. else
  335. echo shar: Extracting \"'a2ul.c'\" \(4528 characters\)
  336. sed "s/^X//" >'a2ul.c' <<'END_OF_FILE'
  337. X/*
  338. X * a2ul - convert Ada-syntax integer literal to unsigned long
  339. X */
  340. X
  341. X#ifndef lint
  342. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  343. X#endif lint
  344. X
  345. X/*
  346. X * This program is free software; you can redistribute it and/or modify
  347. X * it under the terms of the GNU General Public License version 1,
  348. X * as published by the Free Software Foundation.
  349. X *
  350. X * This program is distributed in the hope that it will be useful,
  351. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  352. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  353. X * GNU General Public License for more details.
  354. X *
  355. X * You should have received a copy of the GNU General Public License
  356. X * along with this program; if not, write to the Free Software
  357. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  358. X */
  359. X
  360. X#include <stdio.h>
  361. X#include <howard/port.h>
  362. X#include <howard/version.h>
  363. X
  364. XMODVER ("@(#)$Header: a2ul.c,v 1.7 89/08/11 14:17:25 howard Exp $");
  365. X
  366. X#include <howard/registers.i>
  367. X#include <howard/simultipre.i>
  368. X#include <howard/smp.h>
  369. X
  370. XPUBLIC int a2ul (str, lim, synok, res, end)
  371. XbStrT   str;   /* Input string.*/
  372. XbStrT   lim;   /* Don't pass this.*/
  373. XboolT   synok; /* Accept non-fatal syntax errors.*/
  374. XulongT *res;   /* Points to where to store result.*/
  375. XbStrT  *end;   /* End pointer stored here.*/
  376. X
  377. X/* Function:
  378. X *    
  379. X * Algorithm:
  380. X *    Call a2smp() and then smp2ul().
  381. X * Returns:
  382. X *    
  383. X * Notes:
  384. X *    
  385. X */
  386. X{
  387. XR1 int  s;   /* Return code.*/
  388. X   smpT smp; /* a2smp() stores its result here.*/
  389. X
  390. Xs = a2smp (str, lim, synok, &smp, end);
  391. Xif (SUCCESS == s) s = smp2ul (&smp, res);
  392. Xreturn (s);
  393. X}
  394. X
  395. X#ifdef TEST
  396. X#include <howard/usage.h>
  397. X
  398. XMAINVER ("@(#)$Header: a2ul.c,v 1.7 89/08/11 14:17:25 howard Exp $");
  399. XUSAGE ("integer-numeric-literal");
  400. X
  401. X#include <errno.h>
  402. X#include <limits.h>
  403. X#include <string.h>
  404. X#include <howard/malf.h>
  405. X
  406. XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff)
  407. Xint num; /* Test number.*/
  408. XbStrT str; /* str argument.*/
  409. Xint limoff; /* Limit offset, -1 for none.*/
  410. XboolT synok; /* synok argument.*/
  411. Xint xrc; /* Expected return code.*/
  412. XulongT xres; /* Expected result.*/
  413. Xint xendoff; /* Expected end offset.*/
  414. X{
  415. Xint rc; /* Return code.*/
  416. XulongT res; /* Result stored here.*/
  417. XbStrT end; /* End string stored here.*/
  418. X
  419. Xrc = a2ul (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end);
  420. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  421. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  422. X   PRINTF ("%d: res %lu expected %lu\n", num, res, xres);
  423. Xif (xendoff < 0) xendoff = strlen (str);
  424. Xif ((end - str) != xendoff)
  425. X   PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff);
  426. X}
  427. X
  428. XPUBLIC int main (argc, argv)
  429. Xint    argc; /* Number of arguments.*/
  430. XbStrT *argv; /* Points to array of argument strings.*/
  431. X{
  432. XbStrT end; /* End of string.*/
  433. XulongT res; /* a2ul() stores its result here.*/
  434. X
  435. X/*  num    str            limoff syn rc                     res end */
  436. Xt(__LINE__,"12",              -1, 0,      0, (ulongT)        12, -1);
  437. Xt(__LINE__,"0",               -1, 0,      0, (ulongT)         0, -1);
  438. Xt(__LINE__,"1E6",             -1, 0,      0, (ulongT)   1000000, -1);
  439. Xt(__LINE__,"2#1111_1111#",    -1, 0,      0, (ulongT)       255, -1);
  440. Xt(__LINE__,"16#FF#",          -1, 0,      0, (ulongT)       255, -1);
  441. Xt(__LINE__,"016#0FF#",        -1, 0,      0, (ulongT)       255, -1);
  442. Xt(__LINE__,"16#E#E1",         -1, 0,      0, (ulongT)       224, -1);
  443. Xt(__LINE__,"2#1110_0000#",    -1, 0,      0, (ulongT)       224, -1);
  444. Xt(__LINE__,"012",              1, 0,      0, (ulongT)         0,  1);
  445. Xt(__LINE__,"-2_147_483_648",  -1, 0, ERANGE, (ulongT)         0, -1);
  446. Xt(__LINE__," \t2_147_483_647",-1, 1,      0, (ulongT)  LONG_MAX, -1);
  447. Xt(__LINE__," \t4_294_967_295",-1, 1,      0, (ulongT) ULONG_MAX, -1);
  448. Xt(__LINE__,"4_294_967_296",   -1, 0, ERANGE, (ulongT)         0, 12);
  449. Xt(__LINE__,"12B",             -1, 1,      0, (ulongT)        12,  2);
  450. Xt(__LINE__,"16#abcdef#.",     -1, 1,      0, (ulongT)  0xABCDEF, 10);
  451. Xt(__LINE__,"-2_147_483_649",  -1, 0, ERANGE, (ulongT)         0, -1);
  452. X
  453. Xif (2 != argc) usage();
  454. Xswitch (a2ul (argv[1], NULBSTR, FALSE, &res, &end))
  455. X   {
  456. X   case SUCCESS:
  457. X      PRINTF ("8#%lo#\t10#%lu#\t16#%lX#\n", res, res, res);
  458. X      break;
  459. X   case EINVAL:
  460. X      PRINTF ("EINVAL %s\n", end);
  461. X      break;
  462. X   case EDOM:
  463. X      PRINTF ("EDOM %s\n", end);
  464. X      break;
  465. X   case ERANGE:
  466. X      PRINTF ("ERANGE %s\n", end);
  467. X      break;
  468. X   default:
  469. X      PUTS ("Unexpected return");
  470. X      break;
  471. X   }
  472. Xmfflush (stdout, "Standard Output");
  473. Xexit (SUCCESS);
  474. X
  475. X#ifdef lint
  476. Xreturn (SUCCESS);
  477. X#endif
  478. X}
  479. X#endif
  480. END_OF_FILE
  481. if test 4528 -ne `wc -c <'a2ul.c'`; then
  482.     echo shar: \"'a2ul.c'\" unpacked with wrong size!
  483. fi
  484. # end of 'a2ul.c'
  485. fi
  486. if test -f 'freezePch.b' -a "${1}" != "-c" ; then 
  487.   echo shar: Will not clobber existing file \"'freezePch.b'\"
  488. else
  489. echo shar: Extracting \"'freezePch.b'\" \(2604 characters\)
  490. sed "s/^X//" >'freezePch.b' <<'END_OF_FILE'
  491. X  
  492. X# freezePch.b - make a patch file from one revision to another
  493. X#
  494. X# $Header: freezePch.b,v 1.2 89/09/25 07:01:13 howard Exp $
  495. X#
  496. X# Copyright 1989 Howard Lee Gayle
  497. X# This file is written in the ISO 8859/1 character set.
  498. X# 
  499. X# This program is free software; you can redistribute it and/or modify
  500. X# it under the terms of the GNU General Public License version 1,
  501. X# as published by the Free Software Foundation.
  502. X# 
  503. X# This program is distributed in the hope that it will be useful,
  504. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  505. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  506. X# GNU General Public License for more details.
  507. X# 
  508. X# You should have received a copy of the GNU General Public License
  509. X# along with this program; if not, write to the Free Software
  510. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  511. X# 
  512. X# Shell variables:
  513. X# a - files in old FREEZE file
  514. X# b - files in new FREEZE file
  515. X# n - new FREEZE file, without header
  516. X# o - old FREEZE file, without header
  517. X# r - files to remove
  518. X# s - all new files
  519. X# u - usage string
  520. X
  521. XCMDNAME=freezePch
  522. Xexport CMDNAME
  523. Xu="Usage: $CMDNAME old-revision new-revision"
  524. Xif [ $# -ne 2 ]
  525. Xthen
  526. X   echo "$u" 1>&2
  527. X   exit 1
  528. Xfi
  529. Xa=/tmp/frzpch$$a
  530. Xb=/tmp/frzpch$$b
  531. Xn=/tmp/frzpch$$n
  532. Xo=/tmp/frzpch$$o
  533. Xr=/tmp/frzpch$$r
  534. Xs=/tmp/frzpch$$s
  535. Xco -p -r"$1" FREEZE | \
  536. X   sed -e '1,/^========================================$/d' > $o
  537. Xco -r"$2" FREEZE
  538. Xsed -e '1,/^========================================$/d' FREEZE > $n
  539. Xawk '{print $1}' $o > $a
  540. Xawk '{print $1}' $n > $b
  541. X
  542. Xecho FREEZE > $r
  543. Xcomm -23 $a $b >> $r
  544. Xcat << EOF
  545. X#! /bin/sh
  546. X# This is a shell patch script from revision $1 to revision $2.
  547. XEOF
  548. Xcat << 'EOF'
  549. X# Remove anything before this line, then feed it into a shell. for
  550. X# example by typing "sh file".  This script was created by:
  551. X# $Header: freezePch.b,v 1.2 89/09/25 07:01:13 howard Exp $
  552. X#
  553. X# The following files are to be removed.  If you have a command
  554. X# available to delete files so that they may later be undeleted,
  555. X# you may wish to substitute that command for rm below.  An
  556. X# example of such a command is Jonathan I. Kamens's delete
  557. X# command, posted to comp.sources.unix on 29 March 1989 as volume
  558. X# 18, issues 73-78, archive name undel.
  559. XEOF
  560. Xsed -e 's;^;rm -f ;' $r
  561. X
  562. Xcat << 'EOF'
  563. X#
  564. X# Here is the updated FREEZE file:
  565. XEOF
  566. Xshar FREEZE | grep -v '^exit 0$'
  567. X
  568. Xcomm -13 $a $b > $s
  569. Xif [ -s $s ]
  570. Xthen
  571. X   cat << 'EOF'
  572. X#
  573. X# The following files are all new:
  574. XEOF
  575. X   xargs shar < $s | grep -v '^exit 0$'
  576. Xfi
  577. X
  578. Xjoin -o 1.1 1.2 2.2 $o $n | awk '$2 != $3{print "freezePch0", $0}' | sh
  579. Xecho "echo 'End of shell patch script.'"
  580. Xrm -f $a $b $n $o $r $s
  581. END_OF_FILE
  582. if test 2604 -ne `wc -c <'freezePch.b'`; then
  583.     echo shar: \"'freezePch.b'\" unpacked with wrong size!
  584. fi
  585. # end of 'freezePch.b'
  586. fi
  587. if test -f 'getlin.c' -a "${1}" != "-c" ; then 
  588.   echo shar: Will not clobber existing file \"'getlin.c'\"
  589. else
  590. echo shar: Extracting \"'getlin.c'\" \(3962 characters\)
  591. sed "s/^X//" >'getlin.c' <<'END_OF_FILE'
  592. X/*
  593. X * getlin - read next line from a file
  594. X */
  595. X
  596. X#ifndef lint
  597. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  598. X#endif lint
  599. X
  600. X/*
  601. X * This program is free software; you can redistribute it and/or modify
  602. X * it under the terms of the GNU General Public License version 1,
  603. X * as published by the Free Software Foundation.
  604. X *
  605. X * This program is distributed in the hope that it will be useful,
  606. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  607. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  608. X * GNU General Public License for more details.
  609. X *
  610. X * You should have received a copy of the GNU General Public License
  611. X * along with this program; if not, write to the Free Software
  612. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  613. X */
  614. X
  615. X#include <stdio.h>
  616. X#include <howard/port.h>
  617. X#include <howard/version.h>
  618. X
  619. XMODVER ("@(#)$Header: getlin.c,v 1.7 89/08/09 09:46:03 howard Exp $");
  620. X
  621. X#include <howard/registers.i>
  622. X#include <howard/malf.h>
  623. X
  624. XPUBLIC bStrT getlin (l, ls, f, fn, ln, tw)
  625. XbStrT     l;    /* Points to buffer provided by caller where line
  626. X         * will be stored.*/
  627. Xunsigned  ls;   /* Number of bytes in buffer, including terminal
  628. X         * NUL.  (No space needs to be provided for the
  629. X         * newline since getlin removes it.)*/
  630. XstreamT   f;    /* Input stream.*/
  631. XbStrT     fn;   /* Input file name, for possible error messages.*/
  632. Xunsigned *ln;   /* Points to where current line number is stored.
  633. X         * getlin increments it after a successful read, and
  634. X         * uses it for error messages.*/
  635. XR3 unsigned tw; /* Expand tabs into this many spaces.  0 = no expand.*/
  636. X
  637. X/* Function:
  638. X *    Read one line.  Handle errors.
  639. X * Algorithm:
  640. X *    Read one character at a time until
  641. X *       1) a newline is received,
  642. X *     2) an EOF is received, or
  643. X *     3) the buffer becomes full.
  644. X * Returns:
  645. X *    On success, a pointer to the NUL terminator in l[].
  646. X *    On normal EOF, NULBSTR.
  647. X *    No return on error.
  648. X */
  649. X
  650. X{
  651. XR1 rcharT c;           /* Current input character.*/
  652. XbStrT     bp   = l;    /* Current position in line buffer.*/
  653. Xunsigned  col  = 0;    /* Current column number (leftmost 0).*/
  654. XR2 boolT  more = TRUE; /* Set when more to do.*/
  655. X
  656. Xif ((NULBSTR == fn) || (EOS == B(*fn))) malf1 ("getlin: No file name");
  657. Xif (NULBSTR == l) malf1 ("getlin %s: No line buffer", fn);
  658. Xif (ls < 2) malf1 ("getlin %s: Line buffer too small", fn);
  659. Xif (NULSTRM == f) malf1 ("getlin %s: No FILE", fn);
  660. Xif (((unsigned *) NULL) == ln) malf1 ("getlin %s: No line number pointer", fn);
  661. Xdo
  662. X   {
  663. X   c = getc (f);
  664. X   switch (c)
  665. X      {
  666. X      case '\t':
  667. X         if (0 == tw)
  668. X            {
  669. X            *bp++ = c;
  670. X            ++col;
  671. X            }
  672. X         else
  673. X            {
  674. X            c = tw - (col % tw);
  675. X            col += c;
  676. X            if (col < ls)
  677. X               while (c--)
  678. X                  *bp++ = ' ';
  679. X            }
  680. X         break;
  681. X      case '\n':
  682. X         *bp = EOS;
  683. X         more = FALSE;
  684. X         ++(*ln);
  685. X         break;
  686. X      case EOF:
  687. X         if (ferror (f)) malf1 ("%s: %u: Read error", fn, 1 + *ln);
  688. X         if (bp != l)
  689. X            malf1 ("%s: %u: End of file in middle of line", fn, 1 + *ln);
  690. X         *bp = EOS;
  691. X         bp = NULBSTR;
  692. X         more = FALSE;
  693. X         break;
  694. X      case EOS:  /* NUL.*/
  695. X         malf1 ("%s: %u: NUL in line", fn, 1 + *ln);
  696. X         break;
  697. X      default:
  698. X         *bp++ = c;
  699. X         ++col;
  700. X         break;
  701. X      }
  702. X   if (col == ls) malf1 ("%s: %u: Line too long, %u max", fn, 1 + *ln, ls - 1);
  703. X   }
  704. Xwhile (more);
  705. Xreturn (bp);
  706. X}
  707. X
  708. X
  709. X#ifdef TEST
  710. X#include <howard/usage.h>
  711. X
  712. XMAINVER ("@(#)$Header: getlin.c,v 1.7 89/08/09 09:46:03 howard Exp $");
  713. X
  714. X/* This test driver copies stdin to stdout, converting tabs to
  715. X * spaces like expand(1).*/
  716. X
  717. XUSAGE ("");
  718. X
  719. X#include <howard/malf.h>
  720. X
  721. Xmain()
  722. X{
  723. Xunsigned     ln = 0;
  724. Xstatic byteT l[1024];
  725. X
  726. Xwhile (NULBSTR != getlin (l, 1024, stdin, "Standard Input", &ln, 8))
  727. X   (void) puts (l);
  728. X
  729. Xmfflush (stdout, "Standard Output");
  730. Xexit (SUCCESS);
  731. X
  732. X#ifdef lint
  733. Xreturn (SUCCESS);
  734. X#endif
  735. X}
  736. X#endif
  737. END_OF_FILE
  738. if test 3962 -ne `wc -c <'getlin.c'`; then
  739.     echo shar: \"'getlin.c'\" unpacked with wrong size!
  740. fi
  741. # end of 'getlin.c'
  742. fi
  743. if test -f 'mopenp.c' -a "${1}" != "-c" ; then 
  744.   echo shar: Will not clobber existing file \"'mopenp.c'\"
  745. else
  746. echo shar: Extracting \"'mopenp.c'\" \(3589 characters\)
  747. sed "s/^X//" >'mopenp.c' <<'END_OF_FILE'
  748. X/*
  749. X * mopenp - try to open a file by searching a path
  750. X */
  751. X
  752. X#ifndef lint
  753. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  754. X#endif lint
  755. X
  756. X/*
  757. X * This program is free software; you can redistribute it and/or modify
  758. X * it under the terms of the GNU General Public License version 1,
  759. X * as published by the Free Software Foundation.
  760. X *
  761. X * This program is distributed in the hope that it will be useful,
  762. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  763. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  764. X * GNU General Public License for more details.
  765. X *
  766. X * You should have received a copy of the GNU General Public License
  767. X * along with this program; if not, write to the Free Software
  768. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  769. X */
  770. X
  771. X#include <stdio.h>
  772. X#include <howard/port.h>
  773. X#include <howard/version.h>
  774. X
  775. XMODVER ("@(#)$Header: mopenp.c,v 1.6 89/09/21 07:43:04 howard Exp $");
  776. X
  777. X#include <string.h>
  778. X#include <howard/malf.h>
  779. X#include <howard/registers.i>
  780. X
  781. XPUBLIC streamT mopenp (pth, sep, sim, suf, mod, fnb, len)
  782. X    bStrT    pth; /* Path to search.*/
  783. XR10 rcharT   sep; /* Path separator.*/
  784. XR7  bStrT    sim; /* Simple part of file name.*/
  785. XR8  bStrT    suf; /* Suffix.*/
  786. XR9  bStrT    mod; /* Mode string.*/
  787. XR6  bStrT    fnb; /* Store full file name here.*/
  788. X    unsigned len; /* Length of fnb[].*/
  789. X
  790. X/* Function:
  791. X *    Search pth for a file named sim+suf.  Open it.  Handle errors.
  792. X * Algorithm:
  793. X *    Step through each element of pth.  Assemble the full file name
  794. X *    in fnb[].  Try to open it.  Return on success.
  795. X * Returns:
  796. X *    
  797. X * Notes:
  798. X *    
  799. X */
  800. X{
  801. XR1 bStrT   p1; /* Points to beginning of current path.*/
  802. XR2 bStrT   p2; /* Points to separator at end of current path.*/
  803. XR3 int     i;  /* Path length.*/
  804. XR4 int     m;  /* Max path length.*/
  805. XR5 streamT s;  /* Returned by fopen(3).*/
  806. X
  807. Xif (NULBSTR == pth) malf1 ("mopenp: NULL path");
  808. Xif (EOS == sep)     malf1 ("mopenp: NULL separator character");
  809. Xif (NULBSTR == sim) malf1 ("mopenp: NULL file name");
  810. Xif (NULBSTR == suf) malf1 ("mopenp: NULL suffix");
  811. Xif (NULBSTR == mod) malf1 ("mopenp: NULL mode");
  812. Xif (NULBSTR == fnb) malf1 ("mopenp: NULL file name buffer");
  813. Xm = ((int) len) - 2 - strlen ((cStrT) sim) - strlen ((cStrT) suf);
  814. Xp1 = pth;
  815. Xdo
  816. X   {
  817. X   p2 = (bStrT) strchr ((cStrT) p1, sep);
  818. X   i = ((NULBSTR == p2) ? strlen ((cStrT) p1) : p2 - p1);
  819. X   if ((0 == i) || (i > m))
  820. X      malf1 ("mopenp: path length out of range [1, %d]: %s", m, p1);
  821. X   STRNCPY ((cStrT) fnb, (cStrT) p1, i);
  822. X   p1 = &fnb[i];
  823. X   if ('/' != B(p1[-1])) *p1++ = '/';
  824. X   SPRINTF (p1, "%s%s", sim, suf);
  825. X   s = fopen ((cStrT) fnb, (cStrT) mod);
  826. X   if (NULSTRM != s) return (s);
  827. X   if (NULBSTR != p2) p1 = p2 + 1;
  828. X   }
  829. Xwhile (NULBSTR != p2);
  830. Xmalf1 ("mopenp: no %s%s in %s", sim, suf, pth);
  831. X/*NOTREACHED*/
  832. X}
  833. X
  834. X#ifdef TEST
  835. X#include <howard/usage.h>
  836. X
  837. XMAINVER ("@(#)$Header: mopenp.c,v 1.6 89/09/21 07:43:04 howard Exp $");
  838. XUSAGE ("filename");
  839. X
  840. X#define MLINE 1024 /* Max line length.*/
  841. X
  842. XPUBLIC int main (argc, argv)
  843. Xint    argc; /* Number of arguments.*/
  844. XbStrT *argv; /* Points to array of argument strings.*/
  845. X{
  846. XstreamT is; /* Input stream.*/
  847. Xunsigned     ln = 0; /* Line number.*/
  848. XbyteT fnb[MFILE]; /* Store full paths here.*/
  849. XbyteT lb[MLINE]; /* Line buffer.*/
  850. Xextern  cStrT getenv(); /* (3).*/
  851. X
  852. Xif (2 != argc) usage();
  853. Xis = mopenp ((bStrT) getenv ("EMACSLOADPATH"), ':', argv[1], S(".el"), S("r"),
  854. X             fnb, MFILE);
  855. Xwhile ((NULBSTR != getlin (lb, MLINE, is, fnb, &ln, 0)) && (5 != ln))
  856. X   PUTS (lb);
  857. Xmfflush (stdout, S("Standard Output"));
  858. Xexit (SUCCESS);
  859. X
  860. X#ifdef lint
  861. Xreturn (SUCCESS);
  862. X#endif
  863. X}
  864. X#endif
  865. END_OF_FILE
  866. if test 3589 -ne `wc -c <'mopenp.c'`; then
  867.     echo shar: \"'mopenp.c'\" unpacked with wrong size!
  868. fi
  869. # end of 'mopenp.c'
  870. fi
  871. if test -f 'new.1' -a "${1}" != "-c" ; then 
  872.   echo shar: Will not clobber existing file \"'new.1'\"
  873. else
  874. echo shar: Extracting \"'new.1'\" \(4757 characters\)
  875. sed "s/^X//" >'new.1' <<'END_OF_FILE'
  876. X.\" $Header: new.1,v 1.2 89/09/22 07:24:33 howard Exp $
  877. X.TH NEW 1 "$Revision: 1.2 $"
  878. X.SH NAME
  879. Xnew, new-Make, new-MakeC, new-1, new-3, new-b, new-bib, new-c, new-el, new-h, new-uMake \- create source files from prototypes
  880. X.SH SYNOPSIS
  881. X.B new
  882. X.I filename \&.\|.\|.
  883. X.LP
  884. X.B new-*
  885. X.I filename \&.\|.\|.
  886. X.SH COPYRIGHT
  887. XCopyright \(co 1989 Howard Lee Gayle
  888. X.SH DESCRIPTION
  889. X.I new
  890. Xcreates each of its arguments, and initializes it with a
  891. Xskeleton for the given type of source file.
  892. XIt determines the file type from the suffix, and executes the
  893. Xcorresponding new-* command.
  894. XThis makes it easy to write private versions of new-* commands.
  895. X.SH EXAMPLE
  896. XCreate a C program, a C include file, and the makefiles:
  897. X.nf
  898. X   % new foo.c foo.h MakeCommon uMakefile Makefile
  899. X.fi
  900. X.SH ENVIRONMENT
  901. XIf the environment variable NEWTEXTPATH is set, it is searched
  902. Xfor various files to be included in the prototype.
  903. XThe default is new.txt, which would typically contain a
  904. Xcopyright notice and license information.
  905. XAppropriate comment characters are prepended to each line.
  906. X.PP
  907. XFor manual entries, the files are
  908. X.RI new- section .cprt
  909. Xfor the copyright notice, and
  910. X.RI new- section .txt
  911. Xfor additional text to be included at the end,
  912. X.I e.g.
  913. Xlicense and author sections.
  914. XHere,
  915. X.I section
  916. Xis the manual section number.
  917. X.PP
  918. XFor C programs, the file is new-c.txt.
  919. X.SH FILES
  920. XHere is my new.txt file:
  921. X.nf
  922. X   Copyright 1989 Howard Lee Gayle
  923. X   This file is written in the ISO 8859/1 character set.
  924. X
  925. X   This program is free software; you can redistribute it and/or modify
  926. X   it under the terms of the GNU General Public License version 1,
  927. X   as published by the Free Software Foundation.
  928. X
  929. X   This program is distributed in the hope that it will be useful,
  930. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  931. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  932. X   GNU General Public License for more details.
  933. X
  934. X   You should have received a copy of the GNU General Public License
  935. X   along with this program; if not, write to the Free Software
  936. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  937. X
  938. X.fi
  939. X.PP
  940. XHere is my new-[1-8].cprt file:
  941. X.nf
  942. X   .SH COPYRIGHT
  943. X   Copyright \e(co 1989 Howard Lee Gayle
  944. X.fi
  945. X.PP
  946. XHere is my new-[1-8].txt file:
  947. X.nf
  948. X   .SH LICENSE
  949. X   This program is free software; you can redistribute it and/or modify
  950. X   it under the terms of the GNU General Public License version 1,
  951. X   as published by the Free Software Foundation.
  952. X   .PP
  953. X   This program is distributed in the hope that it will be useful,
  954. X   but WITHOUT ANY WARRANTY; without even the implied warranty of
  955. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  956. X   GNU General Public License for more details.
  957. X   .PP
  958. X   You should have received a copy of the GNU General Public License
  959. X   along with this program; if not, write to the Free Software
  960. X   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  961. X   .SH AUTHOR
  962. X   Howard Gayle,
  963. X   TN/ETX/T/BG,
  964. X   Ericsson Telecom AB,
  965. X   S-126 25 Stockholm,
  966. X   Sweden,
  967. X   howard@ericsson.se,
  968. X   uunet!ericsson.se!howard,
  969. X   Phone: +46 8 719 5565,
  970. X   FAX: +46 8 719 9598,
  971. X   Telex: 14910 ERIC S
  972. X.fi
  973. X.PP
  974. XHere is my new-c.txt file:
  975. X.nf
  976. X   #ifndef lint
  977. X   static char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  978. X   #endif lint
  979. X
  980. X   /*
  981. X    * This program is free software; you can redistribute it and/or modify
  982. X    * it under the terms of the GNU General Public License version 1,
  983. X    * as published by the Free Software Foundation.
  984. X    *
  985. X    * This program is distributed in the hope that it will be useful,
  986. X    * but WITHOUT ANY WARRANTY; without even the implied warranty of
  987. X    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  988. X    * GNU General Public License for more details.
  989. X    *
  990. X    * You should have received a copy of the GNU General Public License
  991. X    * along with this program; if not, write to the Free Software
  992. X    * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  993. X    */
  994. X
  995. X.fi
  996. X.SH LICENSE
  997. XThis program is free software; you can redistribute it and/or modify
  998. Xit under the terms of the GNU General Public License version 1,
  999. Xas published by the Free Software Foundation.
  1000. X.PP
  1001. XThis program is distributed in the hope that it will be useful,
  1002. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  1003. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1004. XGNU General Public License for more details.
  1005. X.PP
  1006. XYou should have received a copy of the GNU General Public License
  1007. Xalong with this program; if not, write to the Free Software
  1008. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1009. X.SH AUTHOR
  1010. XHoward Gayle,
  1011. XTN/ETX/T/BG,
  1012. XEricsson Telecom AB,
  1013. XS-126 25 Stockholm,
  1014. XSweden,
  1015. Xhoward@ericsson.se,
  1016. Xuunet!ericsson.se!howard,
  1017. XPhone: +46 8 719 5565,
  1018. XFAX: +46 8 719 9598,
  1019. XTelex: 14910 ERIC S
  1020. END_OF_FILE
  1021. if test 4757 -ne `wc -c <'new.1'`; then
  1022.     echo shar: \"'new.1'\" unpacked with wrong size!
  1023. fi
  1024. # end of 'new.1'
  1025. fi
  1026. if test -f 'port.h' -a "${1}" != "-c" ; then 
  1027.   echo shar: Will not clobber existing file \"'port.h'\"
  1028. else
  1029. echo shar: Extracting \"'port.h'\" \(4389 characters\)
  1030. sed "s/^X//" >'port.h' <<'END_OF_FILE'
  1031. X/* port.h - Common definitions for portability.
  1032. X *
  1033. X * Copyright 1989 Howard Lee Gayle
  1034. X *
  1035. X * $Header: port.h,v 1.30 89/08/29 08:52:40 howard Exp $
  1036. X *
  1037. X * This program is free software; you can redistribute it and/or modify
  1038. X * it under the terms of the GNU General Public License version 1,
  1039. X * as published by the Free Software Foundation.
  1040. X *
  1041. X * This program is distributed in the hope that it will be useful,
  1042. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1043. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1044. X * GNU General Public License for more details.
  1045. X *
  1046. X * You should have received a copy of the GNU General Public License
  1047. X * along with this program; if not, write to the Free Software
  1048. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1049. X *
  1050. X * Prerequisites: stdio.h.
  1051. X *
  1052. X * Some of the ideas in this file come from the following book,
  1053. X * which I highly recommend:
  1054. X *   Title     Portable C and UNIX system programming
  1055. X *   FullAuthor  J. E. Lapin
  1056. X *   Publisher   Prentice-Hall
  1057. X *   Address     Englewood Cliffs, New Jersey
  1058. X *   Year     1987
  1059. X *   ISBN     0-13-686494-5
  1060. X *   Pages     249
  1061. X * However, all code is original.
  1062. X */
  1063. X
  1064. X#include <howard/cc-lims.i>
  1065. X#include <howard/libc-lims.i>
  1066. X
  1067. X#ifdef NOUCHAR
  1068. Xtypedef char byteT;
  1069. X#define B(x)  ((x) & 0377) /* Access byteT.*/
  1070. X#else /* NOUCHAR*/
  1071. X/* This kludge is to keep lint from generating spurious
  1072. X * messages for every string literal cast to bStrT, e.g. by the
  1073. X * S() macro defined below.*/
  1074. X#ifdef lint
  1075. Xtypedef char byteT;
  1076. X#else /* lint*/
  1077. Xtypedef unsigned char byteT;
  1078. X#endif /* lint*/
  1079. X#define B(x) (x) /* Access byteT.*/
  1080. X#endif /* NOUCHAR*/
  1081. X
  1082. X#ifdef NOULONG
  1083. Xtypedef long ulongT;
  1084. X#else
  1085. Xtypedef unsigned long ulongT;
  1086. X#endif
  1087. X
  1088. X#ifdef NOUSHRT
  1089. Xtypedef unsigned       ushrtT;
  1090. X#else
  1091. Xtypedef unsigned short ushrtT;
  1092. X#endif
  1093. X
  1094. X#ifdef NOVOID
  1095. Xtypedef int void;
  1096. X#endif
  1097. X
  1098. X#ifdef NOVOIDP
  1099. Xtypedef char *voidPT;
  1100. X#else
  1101. Xtypedef void *voidPT;
  1102. X#endif
  1103. X
  1104. Xtypedef int    boolT;   /* Boolean type.*/
  1105. Xtypedef byteT *bStrT;   /* Byte string type.*/
  1106. Xtypedef char  *cStrT;   /* Character string type.*/
  1107. Xtypedef char   flagT;   /* Compact Boolean.*/
  1108. Xtypedef int    rcharT;  /* Character from e.g. getc().*/
  1109. Xtypedef FILE  *streamT; /* Stdio stream.*/
  1110. X
  1111. X#define EOS     '\0'   /* End of string.*/
  1112. X#define FALSE   0      /* Boolean.*/
  1113. X#define MFILE   1024   /* Maximum file name length.*/
  1114. X#define PRIVATE static /* Scope one file.*/
  1115. X#define PUBLIC         /* Exported from this file.*/
  1116. X#define SUCCESS 0      /* Returned by a function on success.*/
  1117. X#define TRUE    1      /* Boolean.*/
  1118. X
  1119. X/* Equality comparison for byte and character strings.
  1120. X * Checking the first byte is before calling strcmp() is for extra
  1121. X * speed. */
  1122. X#define bStrEQ(x,y) ((*(x) == *(y)) && (0 == strcmp ((cStrT)(x),(cStrT)(y))))
  1123. X#define cStrEQ(x,y) ((*(x) == *(y)) && (0 == strcmp ((x),(y))))
  1124. X
  1125. X#define DIG2INT(d) ((int) ((d) - '0')) /* Character of digit to int.*/
  1126. X
  1127. X/* Macros to make lint quieter:*/
  1128. X#define FFLUSH(s)  (void) fflush (s)
  1129. X#define FPRINTF  (void) fprintf
  1130. X#define FPUTS(s,f) (void) fputs(s,f)
  1131. X#define PRINTF  (void) printf
  1132. X#define PUTC(x,p) if(--(p)->_cnt>=0)*(p)->_ptr++=(unsigned char)(x);else(void)_flsbuf((unsigned char)(x),p)
  1133. X#define PUTCHAR(c) (void) putchar(c)
  1134. X#define PUTS(s) (void) puts(s)
  1135. X#define SPRINTF  (void) sprintf
  1136. X#define STRCPY(t,f) (void) strcpy (t, f)
  1137. X#define STRCAT(t,f) (void) strcat (t, f)
  1138. X#define STRNCAT(t,f,n) (void) strncat (t, f, n)
  1139. X#define STRNCPY(t,f,n) (void) strncpy (t, f, n)
  1140. X
  1141. X/* Macros for absolute value, minimum, and maximum:*/
  1142. X#define    ABS(a)   (((a) < 0)   ? (-(a)) : (a))
  1143. X#define    DABS(a)  (((a) < 0.0) ? (-(a)) : (a))
  1144. X#define    MIN(a,b) (((a) < (b)) ? (a) : (b))
  1145. X#define    MAX(a,b) (((a) > (b)) ? (a) : (b))
  1146. X
  1147. X/* NULLs of various types:*/
  1148. X#define NULBSTR  ((bStrT)  NULL) /* NULL byte string.*/
  1149. X#define NULCSTR  ((cStrT)  NULL) /* NULL character string.*/
  1150. X#define NULSTRM  ((streamT)NULL) /* NULL stdio stream.*/
  1151. X
  1152. X/* Cast a "" string literal to a byte string:*/
  1153. X#define S(x)  ((bStrT)(x))
  1154. X
  1155. X/* Number of elements in an array:*/
  1156. X#define ELEMNTS(a) (sizeof(a)/sizeof(*(a)))
  1157. X
  1158. X/* Substitute for missing functions.*/
  1159. X#ifdef NOSTRCHR
  1160. X#define strchr(s,c)   index (s, c)
  1161. X#define strrchr(s,c) rindex (s, c)
  1162. X#endif
  1163. X
  1164. X/* bStrT version of strchr and strrchr: */
  1165. X#define bStrChr(s,c)  ((bStrT) strchr  ((cStrT) (s), (c)))
  1166. X#define bStrRChr(s,c) ((bStrT) strrchr ((cStrT) (s), (c)))
  1167. X
  1168. X#define SPCTAB(c) ((' ' == (c)) || ('\t' == (c))) /* Space or tab.*/
  1169. END_OF_FILE
  1170. if test 4389 -ne `wc -c <'port.h'`; then
  1171.     echo shar: \"'port.h'\" unpacked with wrong size!
  1172. fi
  1173. # end of 'port.h'
  1174. fi
  1175. if test -f 'qrndu.c' -a "${1}" != "-c" ; then 
  1176.   echo shar: Will not clobber existing file \"'qrndu.c'\"
  1177. else
  1178. echo shar: Extracting \"'qrndu.c'\" \(4277 characters\)
  1179. sed "s/^X//" >'qrndu.c' <<'END_OF_FILE'
  1180. X/*
  1181. X * qrndu - uniformly distributed quasi-random long in given range
  1182. X */
  1183. X
  1184. X#ifndef lint
  1185. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1186. X#endif lint
  1187. X
  1188. X/*
  1189. X * This program is free software; you can redistribute it and/or modify
  1190. X * it under the terms of the GNU General Public License version 1,
  1191. X * as published by the Free Software Foundation.
  1192. X *
  1193. X * This program is distributed in the hope that it will be useful,
  1194. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1195. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1196. X * GNU General Public License for more details.
  1197. X *
  1198. X * You should have received a copy of the GNU General Public License
  1199. X * along with this program; if not, write to the Free Software
  1200. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1201. X */
  1202. X
  1203. X#include <stdio.h>
  1204. X#include <howard/port.h>
  1205. X#include <howard/version.h>
  1206. X
  1207. XMODVER ("@(#)$Header: qrndu.c,v 1.7 89/08/14 10:41:31 howard Exp $");
  1208. X
  1209. X#include <limits.h>
  1210. X#include <howard/malf.h>
  1211. X#include <howard/registers.i>
  1212. X
  1213. X#ifdef NORANDOM
  1214. X#ifdef NODRAND48
  1215. X/* Desperation time: neither random(3) nor drand48(3).*/
  1216. X#define MDIFF 32767L /* Max value of h - l.*/
  1217. X#define RAND  rand   /* Function to call for next number.*/
  1218. Xextern int rand();   /* (3).*/
  1219. Xextern int srand();  /* rand(3).*/
  1220. X
  1221. X#else  NODRAND48
  1222. X/* No random(3), but there is drand48(3).*/
  1223. X#define MDIFF LONG_MAX /* Max value of h - l.*/
  1224. X#define RAND  lrand48  /* Function to call for next number.*/
  1225. Xextern long lrand48(); /* drand48(3).*/
  1226. Xextern void srand48(); /* drand48(3).*/
  1227. X#endif NODRAND48
  1228. X
  1229. X#else  NORANDOM
  1230. X/* random(3) is available.*/
  1231. X#define MDIFF LONG_MAX /* Max value of h - l.*/
  1232. X#define RAND  random   /* Function to call for next number.*/
  1233. XPRIVATE char  qrndSt[256]; /* For random()'s state information.    */
  1234. Xextern  cStrT initstate(); /* random(3).*/
  1235. Xextern  long  random();    /* (3).*/
  1236. X#endif NORANDOM
  1237. X
  1238. X/* qrnds - initialize quasi-random number generator with given seed */
  1239. X
  1240. XPUBLIC void qrnds (s)
  1241. Xunsigned s; /* Seed.*/
  1242. X
  1243. X/* Function:
  1244. X *    
  1245. X * Algorithm:
  1246. X *    Call the right function.
  1247. X * Returns:
  1248. X *    
  1249. X * Notes:
  1250. X *    
  1251. X */
  1252. X{
  1253. X#ifdef NORANDOM
  1254. X#ifdef NODRAND48
  1255. X(void) srand ((int) s);
  1256. X#else  NODRAND48
  1257. Xsrand48 ((long) s);
  1258. X#endif NODRAND48
  1259. X#else  NORANDOM
  1260. X(void) initstate (s, qrndSt, sizeof (qrndSt));
  1261. X#endif NORANDOM
  1262. X}
  1263. X
  1264. X/* qrndr - initialize quasi-random number generator with random seed */
  1265. X
  1266. XPUBLIC void qrndr ()
  1267. X
  1268. X/* Function:
  1269. X *    
  1270. X * Algorithm:
  1271. X *    Call qrnds() with the process ID number as seed.
  1272. X * Returns:
  1273. X *    
  1274. X * Notes:
  1275. X *    
  1276. X */
  1277. X{
  1278. Xextern int getpid(); /* (2).*/
  1279. X
  1280. Xqrnds ((unsigned) getpid());
  1281. X}
  1282. X
  1283. XPUBLIC long qrndu (l, h)
  1284. XR4 long l; /* Lower bound.*/
  1285. XR5 long h; /* Upper bound.*/
  1286. X
  1287. X/* Function:
  1288. X *    
  1289. X * Algorithm:
  1290. X *    Check args.  Compute d = h - l.  Compute m = (2 ^ n) - 1,
  1291. X *    where n is ceiling (log2 (d)), where log2 is log to base 2.
  1292. X *    In other words, m is a mask of the form 00000111111... with just
  1293. X *    enough one bits to make m >= d.  Then get a quasi-random number,
  1294. X *    and mask it with m.  If it's too big, loop.  Otherwise scale it
  1295. X *    with l and return it.
  1296. X * Returns:
  1297. X *    
  1298. X * Notes:
  1299. X *    
  1300. X */
  1301. X{
  1302. XR3 ulongT d; /* h - l.*/
  1303. XR1 ulongT m; /* Mask.*/
  1304. XR2 ulongT r; /* Random number.*/
  1305. X
  1306. Xif (l > h) malf1 ("qrndu: empty range [%ld, %ld]", l, h);
  1307. Xif (l == h) return (l);
  1308. Xd = h - l;
  1309. Xif (d > MDIFF) malf1 ("qrndu: range > %ld", MDIFF);
  1310. Xfor (m = 1; m < d; m = (m << 1) | 1)
  1311. X   ;
  1312. Xfor (;;)
  1313. X   {
  1314. X   r = m & RAND();
  1315. X   if (r <= d) return (r + l);
  1316. X   }
  1317. X}
  1318. X
  1319. X#ifdef TEST
  1320. X#include <howard/usage.h>
  1321. X
  1322. XMAINVER ("@(#)$Header: qrndu.c,v 1.7 89/08/14 10:41:31 howard Exp $");
  1323. XUSAGE ("low high [count]");
  1324. X
  1325. X#include <howard/a2.h>
  1326. X
  1327. XPUBLIC int main (argc, argv)
  1328. Xint    argc; /* Number of arguments.*/
  1329. XbStrT *argv; /* Points to array of argument strings.*/
  1330. X{
  1331. Xlong l; /* Lower bound.*/
  1332. Xlong h; /* Upper bound.*/
  1333. XulongT n = 1; /* Number of numbers to generate.*/
  1334. X
  1335. Xif ((3 != argc) && (4 != argc)) usage();
  1336. Xl = ma2l (argv[1], NULBSTR, FALSE, S("Lower bound"), (bStrT *) NULL);
  1337. Xh = ma2l (argv[2], NULBSTR, FALSE, S("Upper bound"), (bStrT *) NULL);
  1338. Xif (4 == argc)
  1339. X   n = ma2ul (argv[3], NULBSTR, FALSE, S("Count"), (bStrT *) NULL);
  1340. Xqrndr();
  1341. Xfor (; 0 != n; --n)
  1342. X   PRINTF ("%ld\n", qrndu (l, h));
  1343. Xmfflush (stdout, "Standard Output");
  1344. Xexit (SUCCESS);
  1345. X
  1346. X#ifdef lint
  1347. Xreturn (SUCCESS);
  1348. X#endif
  1349. X}
  1350. X#endif
  1351. END_OF_FILE
  1352. if test 4277 -ne `wc -c <'qrndu.c'`; then
  1353.     echo shar: \"'qrndu.c'\" unpacked with wrong size!
  1354. fi
  1355. # end of 'qrndu.c'
  1356. fi
  1357. if test -f 'yrwk.c' -a "${1}" != "-c" ; then 
  1358.   echo shar: Will not clobber existing file \"'yrwk.c'\"
  1359. else
  1360. echo shar: Extracting \"'yrwk.c'\" \(4174 characters\)
  1361. sed "s/^X//" >'yrwk.c' <<'END_OF_FILE'
  1362. X/*
  1363. X * yrwk - compute year and ISO week from struct tm
  1364. X */
  1365. X
  1366. X#ifndef lint
  1367. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1368. X#endif lint
  1369. X
  1370. X/*
  1371. X * This program is free software; you can redistribute it and/or modify
  1372. X * it under the terms of the GNU General Public License version 1,
  1373. X * as published by the Free Software Foundation.
  1374. X *
  1375. X * This program is distributed in the hope that it will be useful,
  1376. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1377. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1378. X * GNU General Public License for more details.
  1379. X *
  1380. X * You should have received a copy of the GNU General Public License
  1381. X * along with this program; if not, write to the Free Software
  1382. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1383. X */
  1384. X
  1385. X#include <stdio.h>
  1386. X#include <howard/port.h>
  1387. X#include <howard/version.h>
  1388. X
  1389. XMODVER ("@(#)$Header: yrwk.c,v 1.5 89/08/14 10:01:11 howard Exp $");
  1390. X
  1391. X#include <time.h>
  1392. X#include <tzfile.h>
  1393. X#include <howard/malf.h>
  1394. X#include <howard/registers.i>
  1395. X#include <howard/year.h>
  1396. X
  1397. XPUBLIC unsigned yrwk (tmp, yrp)
  1398. XR4 struct tm *tmp; /* Points to struct tm with input data.*/
  1399. XR5 unsigned  *yrp; /* If non-NULL, year corresponding to week stored here.*/
  1400. X
  1401. X/* Function:
  1402. X *    Return the ISO week number of the date encoded in the struct tm,
  1403. X *    and, if yrp is not NULL, store the year of the ISO week in the
  1404. X *    location to which yrp points.  ISO weeks start on Monday and end
  1405. X *    on Sunday.  ISO week 1 is the first week of a year with four or more
  1406. X *    days in that year.
  1407. X * Algorithm:
  1408. X *    Week is the same for every day in the week, so the week for any day of
  1409. X *    the year is the same as for the day of the year of the Monday of
  1410. X *    that week, assuming negative values are handled correctly.
  1411. X *    Let idw be the ISO day of the week, where 0 = Monday, etc.
  1412. X *    Let i = 10 + tm_yday - idw.  i has the range [4, 375], and has the same
  1413. X *    value for every day in a week.  Here is how i behaves near the
  1414. X *    start of a year:
  1415. X *
  1416. X *    Year Starts On  i For Week Containing Start Of Year  i For Next Week
  1417. X *          Mon = 0     10                                  17
  1418. X *          Tue = 1      9                                  16
  1419. X *          Wed = 2      8                                  15
  1420. X *          Thu = 3      7                                  14
  1421. X *          Fri = 4      6                                  13
  1422. X *          Sat = 5      5                                  12
  1423. X *          Sun = 6      4                                  11
  1424. X *
  1425. X *    If i>=7, then i/7 gives the week number near the start of a year.
  1426. X *
  1427. X *    Here is how i behaves near the end of a non-yeap year:
  1428. X *
  1429. X *    Year Ends On  i For Week Containing End Of Year
  1430. X *       Mon = 0     374
  1431. X *       Tue = 1     373
  1432. X *       Wed = 2     372
  1433. X *       Thu = 3     371
  1434. X *       Fri = 4     370
  1435. X *       Sat = 5     369
  1436. X *       Sun = 6     368
  1437. X *
  1438. X *    If i<=371 then i/7 gives the week number, but if i>371 then the
  1439. X *    week counts as part of the next year.  Leap years require a one-day
  1440. X *    adjustment.
  1441. X * Returns:
  1442. X *    Week number.
  1443. X * Notes:
  1444. X *    
  1445. X */
  1446. X{
  1447. XR1 unsigned i;  /* See above.*/
  1448. XR2 unsigned yr; /* Year.*/
  1449. XR3 unsigned wk; /* Week number.*/
  1450. X
  1451. Xif (((struct tm *) NULL) == tmp) malf1 ("yrwk: NULL struct tm *");
  1452. Xi = 10 + tmp->tm_yday - ((tmp->tm_wday + 6) % 7);
  1453. Xyr  = TM_YEAR_BASE + tmp->tm_year;
  1454. Xif (i > (LEAPYEAR (yr) ? 372 : 371))
  1455. X   {
  1456. X   ++yr;
  1457. X   wk = 1;
  1458. X   }
  1459. Xelse if (i < 7)
  1460. X   {
  1461. X   --yr;
  1462. X   wk = (i + YEARSIZE (yr)) / 7;
  1463. X   }
  1464. Xelse
  1465. X   wk = i / 7;
  1466. Xif (((unsigned *) NULL) != yrp) *yrp = yr;
  1467. Xreturn (wk);
  1468. X}
  1469. X
  1470. X#ifdef TEST
  1471. X#include <howard/usage.h>
  1472. X
  1473. XMAINVER ("@(#)$Header: yrwk.c,v 1.5 89/08/14 10:01:11 howard Exp $");
  1474. XUSAGE ("");
  1475. X
  1476. X#include <sys/types.h>
  1477. X
  1478. XPUBLIC int main (argc, argv)
  1479. Xint    argc; /* Number of arguments.*/
  1480. XbStrT *argv; /* Points to array of argument strings.*/
  1481. X{
  1482. Xtime_t ut; /* Current system time.*/
  1483. Xunsigned w; /* Week.*/
  1484. Xunsigned y; /* Year.*/
  1485. Xextern time_t time(); /* (3).*/
  1486. X
  1487. Xif (1 != argc) usage();
  1488. Xut = time ((time_t *) NULL);
  1489. Xw = yrwk (localtime (&ut), &y);
  1490. XPRINTF ("%u-%02u\n", y, w);
  1491. Xmfflush (stdout, "Standard Output");
  1492. Xexit (SUCCESS);
  1493. X
  1494. X#ifdef lint
  1495. Xreturn (SUCCESS);
  1496. X#endif
  1497. X}
  1498. X#endif
  1499. END_OF_FILE
  1500. if test 4174 -ne `wc -c <'yrwk.c'`; then
  1501.     echo shar: \"'yrwk.c'\" unpacked with wrong size!
  1502. fi
  1503. # end of 'yrwk.c'
  1504. fi
  1505. echo shar: End of archive 4 \(of 9\).
  1506. cp /dev/null ark4isdone
  1507. MISSING=""
  1508. for I in 1 2 3 4 5 6 7 8 9 ; do
  1509.     if test ! -f ark${I}isdone ; then
  1510.     MISSING="${MISSING} ${I}"
  1511.     fi
  1512. done
  1513. if test "${MISSING}" = "" ; then
  1514.     echo You have unpacked all 9 archives.
  1515.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1516. else
  1517.     echo You still need to unpack the following archives:
  1518.     echo "        " ${MISSING}
  1519. fi
  1520. ##  End of shell archive.
  1521. exit 0
  1522.  
  1523.